package com.reserv.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.reserv.dao.MemberDAO;

public class CheckUidServlet extends HttpServlet {
	private MemberDAO dao;
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		dao = MemberDAO.getInstance();
	}
	
	private void doProcess(HttpServletRequest request,
			HttpServletResponse response) throws ServletException,IOException {
		request.setCharacterEncoding("utf-8");
		String isDuplicated = "1";			//기본 true,  1-true 0-false
		String userId = request.getParameter("userId");
		
		if(!dao.checkUid(userId))		//중복되면 true 중복이 아니면 false 리턴
			isDuplicated = "0";
		PrintWriter out = response.getWriter();
		out.println(isDuplicated);
	}
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		doProcess(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		doProcess(request, response);
	}

}
